package com.example.android_contentprovider_message;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView tv_01;
    private ContentResolver cr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv_01 = (TextView) findViewById(R.id.tv_1);


        cr = getContentResolver();
    }
    public void dq(View view){
        Uri uri= Uri.parse("content://sms/");
        Cursor cursor=cr.query(uri,null,null,null,null);
        StringBuffer stringBuffer=new StringBuffer();
        while (cursor.moveToNext()) {
            //如果你还想再获取其他的再这里写就可以了address(手机号码)丶date(日期)等等。
            String id = cursor.getString(cursor.getColumnIndex("body"));
            stringBuffer.append(id+"\n\n");
        }
        tv_01.setText(stringBuffer);
        cursor.close();
    }

}
